package com.orange.modules.dao;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.expert.AuthExpertSchoolMap;
import com.orange.modules.entity.school.AuthSchool;

@Repository
public class AuthSchoolExpertRepository {

	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthSchoolExpertDao authSchoolGroupDao;
	
	/**
	 * 绑定学校
	 */
	public void addAuthSchoolGroupMap(AuthExpertSchoolMap a){
		authSchoolGroupDao.save(a);
	}
	
	/**
	 * 查询申请认证的学校
	 */
	public List<AuthSchool> inspectAuthSchool() throws SQLException{
		String sql = "select a.p_id as pid , a.s_state as state , a.s_fpexpert as fpexpert from t_auth_school a where a.s_state = 1";
		List<AuthSchool> list = dbHelper.getBeanList(sql, AuthSchool.class);
		return list;
	}
	
	/**
	 * 分配专家组考察
	 */
	public AuthSchool updateAuthSchoolFpexpert(String state) throws SQLException{
		String sql = "UPDATE t_auth_school  SET s_fpexpert = '1' where 1 = 1";
		if(state != null || StringUtils.isBlank(state))
			sql += " AND s_state = '"+state+"'";
		AuthSchool a = dbHelper.getBean(sql, AuthSchool.class);
		return a;
	}
}
